﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using PefStudio.StartUp;
using System.Windows.Controls;
using System.Windows;

namespace PefStudio.Windows
{
    public class AbstractMenuItem : MenuItem, IMenuItem
    {
        [Import(Bootstrapper.MainWindowContract, typeof(Window))]
        private Lazy<MainWindow> mainWindow { get; set; }
        protected MainWindow MainWindow
        {
            get { return mainWindow.Value; }
        }

        public AbstractMenuItem()
        {
            this.SubmenuOpened += new RoutedEventHandler(AbstractMenuItem_SubmenuOpened);
            Index = double.MaxValue;
        }

        void AbstractMenuItem_SubmenuOpened(object sender, RoutedEventArgs e)
        {
            foreach (var item in Items)
            {
                if (item is IMenuItem)
                {
                    var menuItem = item as IMenuItem;
                    menuItem.ConditionEvaluate();
                }
            }
        }

        public string ID { get; set; }
        public double Index { get; set; }
        public string InsertRelativeToID { get; set; }
        public bool BeforeRelativeID { get; set; }

        public bool HasSeparator { get; set; }
        public Separator Separator { get; set; }
        public Window ParentWindow { get; set; }

        public virtual void ConditionEvaluate() { }

        public new Visibility Visibility
        {
            get { return base.Visibility; }
            set
            {
                base.Visibility = value;
                if (Separator != null)
                    Separator.Visibility = value;
            }
        }
    }
}
